package daily;

import java.util.ArrayList;
import java.util.List;

/**
 * @author MtRider
 * @version 1.0
 * @description 移动零
 *
 * 输入: nums = [0,1,0,3,12]
 * 输出: [1,3,12,0,0]
 *
 * @GiteeAndGithub MtRider
 * @date 2022/4/23 21:00
 */
public class demo08 {
    public static void main(String[] args) {
        int [] nums={0};
        moveZeroes(nums);
    }

    //ArrayList是有序的用 所以用ArrayLis不是0的接收，是0的最后统一接收
    public static void moveZeroes(int[] nums) {
        List<Integer> list = new ArrayList<>();
        int temp=0;
        for (int num : nums) {
            if(0==num){
                temp++;
            }else{
                list.add(num);
            }
        }
        for (int i = 0; i < temp; i++) {
            list.add(0);
        }
        for (int i = 0; i < list.size(); i++) {
            nums[i]=list.get(i);
        }
    }
}
